package com.example.springbootshell;

import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;

/**
 * @author liyiruo
 * @Description
 * @Date 2024/8/22 下午5:09
 */
@ShellComponent
public class MyCommands {

    @ShellMethod("Say hello to the user.")
    public String hello(String name) {
        return "Hello, " + name + "!";
    }

    @ShellMethod("Add two numbers.")
    public int add(int a, int b) {
        return a + b;
    }

    @ShellMethod("Subtract two numbers.")
    public int subtract(int a, int b) {
        return a - b;
    }

    @ShellMethod("Multiply two numbers.")
    public int multiply(int a, int b) {
        return a * b;
    }

    @ShellMethod("Divide two numbers.")
    public double divide(int a, int b) {
        if (b == 0) {
            throw new IllegalArgumentException("Cannot divide by zero.");
        }
        return (double) a / b;
    }
}
